package com.mistoplus.sedona;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;

public class VortexDetailView extends Activity {

	private ViewFlipper mFilpper;
	private ImageView mImv1;
	private ImageView mImv2;
	private ImageView mImv3;
	private LinearLayout mLyVortexDetailPage;
	private ImageView mImvDetailPage;
	private ImageView mImvDetailPageX;
	
	private ImageView mImvBottomBack;
	private ImageView mImvBottomMusic;
	private ImageView mImvBottomPlay;
	private ImageView mImvBottomSpeech;
	private ImageView mImvBottomBook;
	
	private MediaPlayer mMediaPlayer;
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    setContentView(R.layout.vortex_detail_view);
	    
	    mFilpper = (ViewFlipper)findViewById(R.id.flipper);
	    mImv1 = (ImageView)findViewById(R.id.imv_photo1);
	    mImv2 = (ImageView)findViewById(R.id.imv_photo2);
	    mImv3 = (ImageView)findViewById(R.id.imv_photo3);
	    mLyVortexDetailPage = (LinearLayout)findViewById(R.id.ly_vortex_detail_page);
	    mImvDetailPage = (ImageView)findViewById(R.id.imv_vortex_detail_page);
	    mImvDetailPageX = (ImageView)findViewById(R.id.imv_vortex_detail_page_x);
	    
	    mImvBottomBack = (ImageView)findViewById(R.id.imv_bottom_back);
	    mImvBottomMusic = (ImageView)findViewById(R.id.imv_bottom_music);
	    mImvBottomPlay = (ImageView)findViewById(R.id.imv_bottom_paly);
	    mImvBottomSpeech = (ImageView)findViewById(R.id.imv_bottom_speech);
	    mImvBottomBook = (ImageView)findViewById(R.id.imv_bottom_book);
	    
	    mImvDetailPageX.setOnClickListener(onClick);
	    mImvBottomBack.setOnClickListener(onClick);
	    mImvBottomMusic.setOnClickListener(onClick);
	    mImvBottomPlay.setOnClickListener(onClick);
	    mImvBottomSpeech.setOnClickListener(onClick);
	    mImvBottomBook.setOnClickListener(onClick);
	}

	private OnClickListener onClick = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			switch(v.getId()){
			case R.id.imv_vortex_detail_page_x:
				mLyVortexDetailPage.setVisibility(View.INVISIBLE);
				break;
			case R.id.imv_bottom_book:
				mLyVortexDetailPage.setVisibility(View.VISIBLE);
				break;
			case R.id.imv_bottom_back:
				finish();
				break;
			case R.id.imv_bottom_paly:
				setPlay(v);
				break;
			case R.id.imv_bottom_music:
				break;
			case R.id.imv_bottom_speech:
				break;
			}
		}
	};
	
	private void setPlay(View v){
		if(v.getTag().toString().equals("1")){
			v.setTag("0");
			v.setBackgroundDrawable(getResources().getDrawable(R.drawable.stop));
			startAudio();
		}else{
			v.setTag("1");
			v.setBackgroundDrawable(getResources().getDrawable(R.drawable.play));
			stopAudio();
		}
	}
	private void startAudio(){
		mMediaPlayer = MediaPlayer.create(this, R.raw.nell);
		mMediaPlayer.start();
	}
	private void stopAudio(){
		if(mMediaPlayer != null){
			mMediaPlayer.release();
			mMediaPlayer = null;
		}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		stopAudio();
	}
}
